<?php
/**
 * FastApp.
 * 10/23/24
 * @Author deepsea159
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Account;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Account\SecurityCenterService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "api/securityCenter")]
class SecurityCenterController extends ApiController
{
    #[Inject]
    public SecurityCenterService $service;

    #[GetMapping('getGoogle2FA')]
    public function getGoogle2FA(): ResponseInterface
    {
        return $this->success($this->service->getGoogle2FA());
    }

    #[PostMapping('activeGoogle2FA')]
    public function activeGoogle2FA(): ResponseInterface
    {
        $this->service->activeGoogle2FA($this->validate(['facode' => 'required|string']));
        return $this->success();
    }

    #[PostMapping('resetGoogle2FA')]
    public function resetGoogle2FA(): ResponseInterface
    {
        return $this->success($this->service->resetGoogle2FA($this->validate([
            'type' => 'required|in:2,3',
            'vcode' => 'required',
        ])));
    }

    #[GetMapping('validateGoogle2FA')]
    public function validateGoogle2FA(): ResponseInterface
    {
        $this->service::validateGoogle2FA($this->validate([
            'facode' => 'required|string'
        ])['facode']);
        return $this->success();
    }

    #[GetMapping('loginLog')]
    public function loginLog(): ResponseInterface
    {
        return $this->success($this->service->loginLog());
    }
}